package com.example.demo.common.util;


import com.alibaba.fastjson.JSONObject;

import java.io.Serializable;

/**
 * 自定义返回
 *
 * @Author: 王文龙
 * @Date: 2020/6/1911:13
 * @Version: 1.0
 * @Describe: 描述:
 */
public class JsonResult implements Serializable {

    public static JSONObject success() {
        return success(null);
    }

    public static JSONObject success(Object doc) {
        return build(AbstractStatusValue.OK, doc);
    }

    public static JSONObject fail() {
        return build(AbstractStatusValue.SERVERBUSY, null);
    }

    public static JSONObject fail(StatusValue status) {
        return build(status, null);
    }

    public static JSONObject fail(StatusValue status, Object doc) {
        return build(status, doc);
    }


    public static JSONObject build(StatusValue status, Object doc) {
        JSONObject json = new JSONObject();
        json.put("code", status.getStatus());
        json.put("msg", status.getMsg());
        json.put("result", doc);
        return json;
    }
}
